package com.example.demo;

import java.util.HashMap;

/**
 * @Description : TODO
 * @Author : ZYX
 * @Date : 2022/9/13 22:39
 * @Version : 1.0
 **/
public class ByteDemo {

    public static void main(String[] args) {
        String exStr = "abcabcdeabcd";
        HashMap<String, Integer> map = new HashMap<>();

        // 标志位和结果
        int position = 1;
        int result = 0;

        for (int i = 0; i < exStr.length(); i++) {
            String key = String.valueOf(exStr.charAt(i));

            if (i == exStr.length()-1){
                result = result > i-position+1 ? result:i-position+1;
            }
            if (map.containsKey(key)){
                result = result > i-position+1 ? result:i-position+1;
                position = i;
                map.clear();
                map.put(key,1);
            }else {
                map.put(key,1);
            }

        }

        System.out.println(result);

    }

}
